<?php require_once ADMINVIEWPATH.'admin_header.php'; ?>
<?php require_once ADMINVIEWPATH.'admin_menu.php'; ?>
<!-- Page Content -->
            <div class="page-content">
                <!-- Page Breadcrumb -->
                <div class="page-breadcrumbs">
                    <ul class="breadcrumb">
                        <li>
                            <i class="fa fa-home"></i>
                            <a href="/luckydog/index">首页</a>
                        </li>
                        <li class="">
                            <a href="#">转盘活动</a>
                        </li>
                        <li class="">
                            抽奖奖品列表
                        </li>
                    </ul>
                </div>
                <!-- /Page Breadcrumb -->
                <!-- Page Body -->
                <div class="page-body">
                    <div class="row">
                        <div class="col-xs-12 col-md-12">
                            <div class="tab-content tabs-flat no-padding">
                                <div id="visits" class="tab-pane active animated fadeInUp">
                                    <div class="row">
                                        <div class="col-lg-12 chart-container">
                                            <div id="dashboard-chart-visits" class="chart chart-lg no-margin">
                                                <div class="widget-body">
                                                        <div class="table-toolbar">
                                                            <?php if(check_authorize("Luckydraw","List","add")):?>
                                                            <a id="editabledatatable_new" href="javascript:;"  class="js_add btn btn-default">
                                                                添加要抽奖的奖品
                                                            </a>
                                                            <?php endif;?>
                                                            <span style="color:red">（注：前端仅能显示8件奖品）</span>
                                                        </div>
                                                        <table class="table table-striped table-bordered table-hover" id="simpledatatable">
                                                            <thead>
                                                                <tr>
                                                                    <th style="width: 60px;">奖品ID</th>
                                                                    <th>标题</th>
                                                                    <th>封面图</th>
                                                                    <th>中奖概率</th>
                                                                    <th>市场价</th>
                                                                    <th>库存量</th>
                                                                    <th>添加时间</th>
                                                                    <th>状态</th>
                                                                    <th>操作</th>
                                                                </tr>
                                                            </thead>
                                                            <tbody>
                                                            <?php if(!empty($luckydraw_list)):?>
                                                            <?php foreach($luckydraw_list as $key=> $row):?>
                                                                <tr class="gradeX <?php if($row['isempty'] == 1):?>warning<?php endif;?>">
                                                                    <td class="center" style="text-align:center;width:40px;"><?= $row['id'];?></td>
                                                                    <td class="center"  data-id = "<?= $row['id'];?>" ><?= $row['title'];?></td>
                                                                    <td class="center " >
                                                                        <img width="150" height="80" src="<?= OSSHOST.$row['cover'];?>">
                                                                        <?php if($row['isempty'] == 1):?><b style="color:red;">空奖</b><?php endif;?>
                                                                    </td>
                                                                    <td class="center" ><?= $row['chance'];?>%</td>
                                                                    <td class="center" ><?= $row['price'];?></td>
                                                                    <td class="center" ><?= $row['stock'];?></td>
                                                                    <td class="center"><?=  date("Y-m-d",$row['addtime'])?></td>
                                                                    <td class="center">
                                                                        <?php if($row['onlinestatus'] == 1){?>
                                                                            上架
                                                                        <?php }elseif($row['onlinestatus'] == 0){?>
                                                                            下架
                                                                        <?php }?>
                                                                    </td>
                                                                    <td class="center "  data_id = "<?= $row['id'];?>">
                                                                        <?php if(check_authorize("Luckydraw","List","edit")):?>
                                                                        <a style="color:blue;" href="/luckydog/luckydraw/edit?id=<?= $row['id']?>" >修改</a>&nbsp;|
                                                                        <?php endif;?>
                                                                        <?php if(check_authorize("Luckydraw","List","publish")):?>
                                                                        <a  style="color:blue;" href="javascript:;" class="J_onlinestatus" type="onlinestatus" onlinestatus="<?= $row['onlinestatus'];?>" >
                                                                            <?php if($row['onlinestatus'] == 1){?>
                                                                                下架
                                                                            <?php }elseif($row['onlinestatus'] == 0){?>
                                                                                上架
                                                                            <?php }?>
                                                                        </a>|
                                                                        <?php endif;?>
                                                                        <?php if(check_authorize("Luckydraw","List","delete")):?>
                                                                        <a style="color:blue;" href="javascript:;" class="J_del">删除</a>
                                                                        <?php endif;?>
                                                                    </td>
                                                                </tr>
                                                        <?php endforeach;?>
                                                        <?php endif;?>
                                                                <tr>
                                                                    <td align='center' colspan="8">
                                                                        <div class="page_links"><?= $page_links?></div>
                                                                    </td>
                                                                </tr>
                                                            </tbody>
                                                        </table>
                                                    </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /Page Body -->
        </div>
        <input type="hidden" id="total_chance" value="<?=$total_chance?>">
        <!-- /Page Content -->
<script src="<?= STATICURL; ?>js/jquery-2.0.3.min.js"></script>
<script src="<?= STATICURL; ?>layer/layer.js"></script>
<?php require_once ADMINVIEWPATH.'admin_footer.php'; ?>
<script>
    $(document).ready(function(){
        $(".js_add").click(function(){
            var total_online_row = "<?=$total_online_row?>";
            if(total_online_row >=8)
            {
                layer.msg("当前线上展示个数是8个，请下架或删除其他奖品再继续添加");
                return false;
            }
            location = "/luckydog/luckydraw/add";
        });


        $('.luckydrawDetail').on('click', function(){
            //iframe窗
            var id = $(this).attr("data-id");
            layer.open({
                type: 2,
                title: '奖品详情',
                shade: [0.5, '#000'],
                shadeClose: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['650px', '540px'],
                content: '/luckydog/luckydraw/detail?id='+id
            });
        });
        $(".J_del").click(function() {
            var id = $(this).parent().attr("data_id");
            if (confirm("您确定要删除吗？")) {
                $.post("/luckydog/luckydraw/do_del", {"id":id}, function(res) {
                    if (res) {
                        window.location.reload();
                    }else{
                        alert("删除失败");
                    }
                });
            }
        }); 

        $(".J_onlinestatus").click("click",function(){
            var id = $(this).parent().attr("data_id");
            var onlinestatus = $(this).attr("onlinestatus");
            var des = "确定上架吗？";
            if(onlinestatus == 1){
                onlinestatus = 0;
                des = "确定要下架吗？";
            }else{
                onlinestatus = 1;
            }
            if(confirm(des)){
                $.post("/luckydog/luckydraw/editStatus",{"id":id,"onlinestatus":onlinestatus,"type":"onlinestatus"},function(res){
                    if(res){
                         window.location.reload();
                    }else{
                        alert("添加失败");
                    }
                });
            }
        });   
    });
</script>



